﻿using MediatR;
using T_settlement.API.Application.Command.settlementCommand;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.settlementCommandHandlers
{
    public class PDelSettlementCommandHandlers:IRequestHandler<PDelSettlementCommand,int>
    {
        private readonly lsettlementRepository lsettlementRepository;

        public PDelSettlementCommandHandlers(lsettlementRepository lsettlementRepository)
        {
            this.lsettlementRepository = lsettlementRepository;
        }

        public  async Task<int> Handle(PDelSettlementCommand request, CancellationToken cancellationToken)
        {
            var Id = request.SettlementId.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await lsettlementRepository.GetAsync(x=>Id.Contains(x.SettlementId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await lsettlementRepository.UpdateAsyncRange(list);
        }
    }
}
